package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.UserResumeDAO;
import com.yang.doctorrecruitment.dto.SchoolExperience;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class SchoolSituationAction extends ActionSupport {
    public SchoolExperience schoolexperience;
    public String SchoolExperience(){
        String HonourOne= NullChange.NullChange(schoolexperience.getHonourOne());
        String HonourTwo= NullChange.NullChange(schoolexperience.getHonourTwo());
        String HonourThree= NullChange.NullChange(schoolexperience.getHonourThree());
        int GradeOne=schoolexperience.getGradeOne();
        int GradeTwo=schoolexperience.getGradeTwo();
        int GradeThree=schoolexperience.getGradeThree();
        String Previous=NullChange.NullChange(schoolexperience.getPrevious());
        int Politic=schoolexperience.getPolitic();
        JSONObject json=new JSONObject();
        json.put("HonourOne",HonourOne);
        json.put("HonourTwo",HonourTwo);
        json.put("HonourThree",HonourThree);
        json.put("GradeOne",GradeOne);
        json.put("GradeTwo",GradeTwo);
        json.put("GradeThree",GradeThree);
        json.put("Previous",Previous);
        json.put("Politic",Politic);
        String jsonString =json.toJSONString();
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");

        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        boolean res= UserResumeDAO.updataSchoolSituation(jsonString,UserID);
        if(res){
            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }

    }
    public SchoolExperience getSchoolexperience() {
        return schoolexperience;
    }

    public void setSchoolexperience(SchoolExperience schoolexperience) {
        this.schoolexperience = schoolexperience;
    }
}
